//
//  JJHomeBottomView.swift
//  JJSina
//
//  Created by mac on 2017/12/7.
//  Copyright © 2017年 xinyuan. All rights reserved.
//

import UIKit

class JJHomeBottomView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - 设置视图
    func setupUI() {
        backgroundColor = JJ_THEMECOLOR
        // 添加按钮
        let retweetBtn = addChildButton(imageName: "timeline_icon_retweet", title: "转发")
        let commentBtn = addChildButton(imageName: "timeline_icon_comment", title: "评论")
        let unlikeBtn = addChildButton(imageName: "timeline_icon_unlike", title: "赞")
        // 添加竖线
        let line1 = addChildLine()
        let line2 = addChildLine()
        // 添加约束
        retweetBtn.snp.makeConstraints { (make) in
            make.left.top.bottom.equalToSuperview()
            make.width.equalTo(commentBtn.snp.width)
        }
        commentBtn.snp.makeConstraints { (make) in
            make.top.bottom.equalToSuperview()
            make.left.equalTo(retweetBtn.snp.right)
            make.width.equalTo(unlikeBtn.snp.width)
        }
        unlikeBtn.snp.makeConstraints { (make) in
            make.top.bottom.equalToSuperview()
            make.left.equalTo(commentBtn.snp.right)
            make.right.equalToSuperview()
        }
        line1.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.centerX.equalTo(retweetBtn.snp.right)
        }
        line2.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.centerX.equalTo(commentBtn.snp.right)
        }
    }
    
}
// MARK: - 创建子控件
extension JJHomeBottomView {
    // 添加底部按钮
    func addChildButton(imageName: String, title: String)-> UIButton {
        let btn = UIButton()
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), for: UIControlState.normal)
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), for: UIControlState.highlighted)
        btn.setImage(UIImage(named: imageName), for: UIControlState.normal)
        btn.setTitle(title, for: UIControlState.normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: JJ_MIDDLE_FONTSIZE)
        btn.setTitleColor(UIColor.darkGray, for: UIControlState.normal)
        btn.sizeToFit()
        addSubview(btn)
        return btn
    }
    // 添加按钮间的线
    func addChildLine()-> UIImageView {
        let imgV = UIImageView(imageName: "timeline_card_bottom_line")
        addSubview(imgV)
        return imgV
    }
}























